package br.uece.laconi.tac.adapt;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;

import br.uece.laconi.tac.Agent;
import br.uece.laconi.tac.strategy.EntertainmentStrategy;

/**
 * @author robson
 */
public class AdaptBehavior extends Timer {
	public Agent agent = null;	
	public Logger log = null;
	
	public AdaptBehavior(Agent agent) {
		this.agent = agent;
		log = Logger.getLogger(agent.getClass().getName());
	}
	
	/**
	 * @param parameters = referencia do objeto com a estrategia de entretenimento para ser adaptado
	 */	
	public void init(long delay){
		TimerTask risc;
		risc = new AdaptBehaviorJob(agent.es);
		new Timer().schedule(risc, delay);
	}

	class AdaptBehaviorJob extends TimerTask {
		EntertainmentStrategy strategy;
		public AdaptBehaviorJob (Object parameters) {
			this.strategy = (EntertainmentStrategy)parameters;
			System.out.println("Inicializando Listener em " + new Date().toString());
		 }
		 public void run() {
			//JOptionPane.showMessageDialog(null, "SellAgentWithRiscAverse as " + new Date().toString(), "SellAgentWithRiscAverse as " +new Date().toString() , JOptionPane.ERROR_MESSAGE);
			strategy.adaptAgent();
			this.cancel();
		}
	} 
}